package com.pinfly.common.util;

import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;

/**
 * An adapter class for building SAX ContentHandler classes.
 * 
 * This class provides implementation for all the methods in the SAX
 * ContentHandler interface. It is useful as a base class for constructing
 * Content Handlers. All of the method implementations are empty except for
 * setDocumentLocator, which saves the Locator in a protected member variable
 * called m_locator. This can be accessed by derived classes.
 * 
 * The derived classes only need to provide implementations for the methods they
 * are actually interested in. This follows the pattern used in AWT event
 * adapter classes.
 * 
 */

public abstract class SAXContentHandlerAdapter implements ContentHandler
{
    protected Locator m_locator;

    /** Default constructor */
    public SAXContentHandlerAdapter ()
    {
    }

    /**
     * Save the document locator object.
     * 
     * The locator can be used to determine where location in the document when
     * other methods are called
     */
    public void setDocumentLocator (Locator loc)
    {
        m_locator = loc;
    }

    /**
     * Start of the document
     * 
     * @throws SAXException When things go wrong.
     */
    public void startDocument () throws SAXException
    {
    }

    /**
     * End of the document
     * 
     * @throws SAXException When things go wrong.
     */
    public void endDocument () throws SAXException
    {
    }

    /**
     * Processing instruction
     * 
     * @param target String containing the target of the PI
     * @param data String containing the data sent to the PI. This typically
     *            looks like one or more attribute/value pairs.
     * 
     * @throws SAXException When things go wrong.
     */
    public void processingInstruction (String target, String data) throws SAXException
    {
    }

    /**
     * Start namespace prefix mapping.
     * 
     * Although this typically occurs within the root element of an XML
     * document, it can occur at any point within the document. Note that a
     * prefix mapping on an element triggers this callback before the callback
     * for the actual element itself occurs.
     * 
     * @param prefix String used for the namespace being reported.
     * @param uri String containing the URI for the namespace being reported.
     * 
     * @throws SAXException When things go wrong.
     */
    public void startPrefixMapping (String prefix, String uri) throws SAXException
    {
    }

    /**
     * End of a namespace prefix mapping.
     * 
     * @param prefix Mapping that is no longer available
     * 
     * @throws SAXException When things go wrong.
     */
    public void endPrefixMapping (String prefix) throws SAXException
    {
    }

    /**
     * Beginning of an element.
     * 
     * This reports the occurrence of an actual element. It includes the
     * element's attributes, with the exception of XML vocabulary specific
     * attributes, such as xlmns: and xsi:.
     * 
     * @param namespace The namespace URI this element is associated with, or an
     *            empty String.
     * @param localName The name of the element, with no namespace prefix.
     * @param rawName The full XML 1.0 version of the name: [namespace
     *            prefix]:[localName]
     * @param atts Attributes list for this element
     * 
     * @throws SAXException When things go wrong.
     */
    public void startElement (String namespace, String localName, String rawName, Attributes atts) throws SAXException
    {
    }

    /**
     * End of an element.
     * 
     * Note that this is called for both empty and non-empty elements.
     * 
     * @param namespace The namespace URI this element is associated with, or an
     *            empty String.
     * @param localName The name of the element, with no namespace prefix.
     * @param rawName The full XML 1.0 version of the name: [namespace
     *            prefix]:[localName]
     * 
     * @throws SAXException When things go wrong.
     */
    public void endElement (String namespace, String localName, String rawName) throws SAXException
    {
    }

    /**
     * Character data within an element.
     * 
     * Note that only the data between the locations specified by start and end
     * is guaranteed to be valid.
     * 
     * @param ch Character array containing the character data
     * @param start Index into array where data starts
     * @param length Number of characters
     * 
     * @throws SAXException When things go wrong.
     */
    public void characters (char[] ch, int start, int length) throws SAXException
    {
    }

    /**
     * Ignorable white space.
     * 
     * This reports white space that can be ignored in the originating document.
     * This is typicall invoked only when validation is occurring in the parsing
     * process.
     * 
     * @param ch Character array containing the character data
     * @param start Index into array where data starts
     * @param length Number of characters
     * 
     * @throws SAXException When things go wrong.
     */
    public void ignorableWhitespace (char[] ch, int start, int length) throws SAXException
    {
    }

    /**
     * Skipped entity.
     * 
     * This reports an entity that is skipped by the parser. This should only
     * happen with non-validating parsers, and even then is
     * implementation-dependent behavior.
     * 
     * @param name Name of the entity being skipped.
     * 
     * @throws SAXException When things go wrong.
     */
    public void skippedEntity (String name) throws SAXException
    {
    }

}
